Components
TYPE_COMPONENT_MAPPING = {ComponentType.ACTION_ROW: ActionRow, ComponentType.BUTTON: Button, ComponentType.STRING_SELECT: StringSelectMenu, ComponentType.USER_SELECT: UserSelectMenu, ComponentType.CHANNEL_SELECT: ChannelSelectMenu, ComponentType.ROLE_SELECT: RoleSelectMenu, ComponentType.MENTIONABLE_SELECT: MentionableSelectMenu}
module-attribute
¶
BaseComponent
¶
Bases: DictSerializationMixin
A base component class.
Warning
This should never be directly instantiated.
Source code in interactions\models\discord\components.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
type: ComponentType
class-attribute
¶
from_dict(data)
classmethod
abstractmethod
¶
Create a component from a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | dict | the dictionary to create the component from | required |
Returns:
Type | Description |
---|---|
BaseComponent | The created component. |
Source code in interactions\models\discord\components.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
from_dict_factory(data, *, alternate_mapping=None)
classmethod
¶
Creates a component from a payload.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | dict | the payload from Discord | required |
alternate_mapping | dict[ComponentType, BaseComponent] | None | an optional mapping of component types to classes | None |
Source code in interactions\models\discord\components.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
InteractiveComponent
¶
Bases: BaseComponent
A base interactive component class.
Warning
This should never be instantiated.
Source code in interactions\models\discord\components.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
ActionRow
¶
Bases: BaseComponent
Represents an action row.
Attributes:
Name | Type | Description |
---|---|---|
components | list[Dict | BaseComponent] | A sequence of components contained within this action row |
Source code in interactions\models\discord\components.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
components: list[Dict | BaseComponent] = [BaseComponent.from_dict_factory(c) if isinstance(c, dict) else c for c in components]
instance-attribute
¶
type: ComponentType = ComponentType.ACTION_ROW
instance-attribute
¶
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
127 128 129 |
|
add_component(*components)
¶
Add a component to this action row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*components | dict | BaseComponent | The component(s) to add. | () |
Source code in interactions\models\discord\components.py
134 135 136 137 138 139 140 141 142 143 144 145 |
|
split_components(*components, count_per_row=5)
classmethod
¶
Split components into action rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*components | dict | BaseComponent | The components to split. | () |
count_per_row | int | The amount of components to have per row. | 5 |
Returns:
Type | Description |
---|---|
list[ActionRow] | A list of action rows. |
Source code in interactions\models\discord\components.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
186 187 188 189 190 |
|
Button
¶
Bases: InteractiveComponent
Represents a discord ui button.
Attributes:
Name | Type | Description |
---|---|---|
style | optional[ButtonStyle, int] | Buttons come in a variety of styles to convey different types of actions. |
label | optional[str] | The text that appears on the button, max 80 characters. |
emoji | optional[Union[PartialEmoji, dict, str]] | The emoji that appears on the button. |
custom_id | Optional[str] | A developer-defined identifier for the button, max 100 characters. |
url | Optional[str] | A url for link-style buttons. |
disabled | bool | Disable the button and make it not interactable, default false. |
Source code in interactions\models\discord\components.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
Styles: ButtonStyle = ButtonStyle
class-attribute
¶
style: ButtonStyle = ButtonStyle(style)
instance-attribute
¶
label: str | None = label
instance-attribute
¶
emoji: PartialEmoji | None = emoji
instance-attribute
¶
custom_id: str | None = custom_id
instance-attribute
¶
url: str | None = url
instance-attribute
¶
disabled: bool = disabled
instance-attribute
¶
type: ComponentType = ComponentType.BUTTON
instance-attribute
¶
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
242 243 244 245 246 247 248 249 250 251 252 253 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
BaseSelectMenu
¶
Bases: InteractiveComponent
Represents a select menu component
Attributes:
Name | Type | Description |
---|---|---|
custom_id | str | A developer-defined identifier for the button, max 100 characters. |
placeholder | str | The custom placeholder text to show if nothing is selected, max 100 characters. |
min_values | Optional[int] | The minimum number of items that must be chosen. (default 1, min 0, max 25) |
max_values | Optional[int] | The maximum number of items that can be chosen. (default 1, max 25) |
disabled | bool | Disable the select and make it not intractable, default false. |
type | Union[ComponentType, int] | The action role type number defined by discord. This cannot be modified. |
Source code in interactions\models\discord\components.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
custom_id: str = custom_id or str(uuid.uuid4())
instance-attribute
¶
placeholder: str | None = placeholder
instance-attribute
¶
min_values: int = min_values
instance-attribute
¶
max_values: int = max_values
instance-attribute
¶
disabled: bool = disabled
instance-attribute
¶
type: ComponentType = MISSING
instance-attribute
¶
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
304 305 306 307 308 309 310 311 312 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
317 318 319 320 321 322 323 324 325 |
|
StringSelectOption
¶
Bases: BaseComponent
Represents a select option.
Attributes:
Name | Type | Description |
---|---|---|
label | str | The label (max 80 characters) |
value | str | The value of the select, this is whats sent to your bot |
description | Optional[str] | A description of this option |
emoji | Optional[Union[PartialEmoji, dict, str] | An emoji to show in this select option |
default | bool | Is this option selected by default |
Source code in interactions\models\discord\components.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
label: str = label
instance-attribute
¶
value: str = value
instance-attribute
¶
description: str | None = description
instance-attribute
¶
emoji: PartialEmoji | None = emoji
instance-attribute
¶
default: bool = default
instance-attribute
¶
converter(value)
classmethod
¶
Source code in interactions\models\discord\components.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
374 375 376 377 378 379 380 381 382 383 384 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
389 390 391 392 393 394 395 396 397 398 399 400 |
|
StringSelectMenu
¶
Bases: BaseSelectMenu
Represents a string select component.
Attributes:
Name | Type | Description |
---|---|---|
options | List[dict] | The choices in the select, max 25. |
custom_id | str | A developer-defined identifier for the button, max 100 characters. |
placeholder | str | The custom placeholder text to show if nothing is selected, max 100 characters. |
min_values | Optional[int] | The minimum number of items that must be chosen. (default 1, min 0, max 25) |
max_values | Optional[int] | The maximum number of items that can be chosen. (default 1, max 25) |
disabled | bool | Disable the select and make it not intractable, default false. |
type | Union[ComponentType, int] | The action role type number defined by discord. This cannot be modified. |
Source code in interactions\models\discord\components.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
|
options: list[StringSelectOption] = [StringSelectOption.converter(option) for option in options]
instance-attribute
¶
type: ComponentType = ComponentType.STRING_SELECT
instance-attribute
¶
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
443 444 445 446 447 448 449 450 451 452 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
457 458 459 460 461 |
|
UserSelectMenu
¶
Bases: BaseSelectMenu
Represents a user select component.
Attributes:
Name | Type | Description |
---|---|---|
custom_id | str | A developer-defined identifier for the button, max 100 characters. |
placeholder | str | The custom placeholder text to show if nothing is selected, max 100 characters. |
min_values | Optional[int] | The minimum number of items that must be chosen. (default 1, min 0, max 25) |
max_values | Optional[int] | The maximum number of items that can be chosen. (default 1, max 25) |
disabled | bool | Disable the select and make it not intractable, default false. |
type | Union[ComponentType, int] | The action role type number defined by discord. This cannot be modified. |
Source code in interactions\models\discord\components.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
|
type: ComponentType = ComponentType.USER_SELECT
instance-attribute
¶
RoleSelectMenu
¶
Bases: BaseSelectMenu
Represents a user select component.
Attributes:
Name | Type | Description |
---|---|---|
custom_id | str | A developer-defined identifier for the button, max 100 characters. |
placeholder | str | The custom placeholder text to show if nothing is selected, max 100 characters. |
min_values | Optional[int] | The minimum number of items that must be chosen. (default 1, min 0, max 25) |
max_values | Optional[int] | The maximum number of items that can be chosen. (default 1, max 25) |
disabled | bool | Disable the select and make it not intractable, default false. |
type | Union[ComponentType, int] | The action role type number defined by discord. This cannot be modified. |
Source code in interactions\models\discord\components.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
|
type: ComponentType = ComponentType.ROLE_SELECT
instance-attribute
¶
MentionableSelectMenu
¶
Bases: BaseSelectMenu
Source code in interactions\models\discord\components.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
type: ComponentType = ComponentType.MENTIONABLE_SELECT
instance-attribute
¶
ChannelSelectMenu
¶
Bases: BaseSelectMenu
Source code in interactions\models\discord\components.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
|
channel_types: list[ChannelType] | None = channel_types or []
instance-attribute
¶
type: ComponentType = ComponentType.CHANNEL_SELECT
instance-attribute
¶
ChannelTypes: ChannelType = ChannelType
class-attribute
¶
from_dict(data)
classmethod
¶
Source code in interactions\models\discord\components.py
575 576 577 578 579 580 581 582 583 584 |
|
to_dict()
¶
Source code in interactions\models\discord\components.py
589 590 591 592 593 |
|
process_components(components)
¶
Process the passed components into a format discord will understand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
components | Optional[Union[List[List[Union[BaseComponent, Dict]]], List[Union[BaseComponent, Dict]], BaseComponent, Dict]] | List of dict / components to process | required |
Returns:
Type | Description |
---|---|
List[Dict] | formatted dictionary for discord |
Raises:
Type | Description |
---|---|
ValueError | Invalid components |
Source code in interactions\models\discord\components.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
|
spread_to_rows(*components, max_in_row=5)
¶
A helper function that spreads your components into ActionRow
s of a set size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*components | Union[ActionRow, Button, StringSelectMenu] | The components to spread, use | () |
max_in_row | int | The maximum number of components in each row | 5 |
Returns:
Type | Description |
---|---|
List[ActionRow] | List[ActionRow] of components spread to rows |
Raises:
Type | Description |
---|---|
ValueError | Too many or few components or rows |
Source code in interactions\models\discord\components.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
|
get_components_ids(component)
¶
Creates a generator with the custom_id
of a component or list of components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component | Union[str, dict, list, InteractiveComponent] | Objects to get | required |
Returns:
Type | Description |
---|---|
Iterator[str] | Generator with the |
Raises:
Type | Description |
---|---|
ValueError | Unknown component type |
Source code in interactions\models\discord\components.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
Created: January 28, 2023